package com.yiren.dbaa.view.interf.impl;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.LineString;
import com.yiren.backstage.currency.bean.GpsInfoBean;
import com.yiren.backstage.currency.bean.PointBean;
import com.yiren.backstage.currency.bean.PointExBean;
import com.yiren.dbaa.util.JtsUtils;
import com.yiren.dbaa.view.interf.IGeometryCreate;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by WANGRONGXIANG
 * on 2022/4/14
 * Describe 集合图形生成实现类
 */
public class GeometryCreateImpl implements IGeometryCreate {

    @Override
    public LineString[] getCarLineString(List<PointBean> carPoints) {
        LineString[] lineStrings = new LineString[2];
        if (null != carPoints && null != carPoints.get(0)) {
            List<Coordinate> carCoordinates = new ArrayList<>();
            List<Coordinate> wheelCoordinates = new ArrayList<>();
            JtsUtils jtsUtils = new JtsUtils();
            for (int i = 1; i <= 24; i++) {
                if (i == 6 || i == 7 || i == 8 || i == 18 || i == 19 || i == 20) {
                    continue;
                }
                carCoordinates.add(jtsUtils.createPoint(carPoints.get(i)));
            }
            wheelCoordinates.add(jtsUtils.createPoint(carPoints.get(25)));
            wheelCoordinates.add(jtsUtils.createPoint(carPoints.get(29)));
            wheelCoordinates.add(jtsUtils.createPoint(carPoints.get(31)));
            wheelCoordinates.add(jtsUtils.createPoint(carPoints.get(27)));
            lineStrings[0] = jtsUtils.createLine(carCoordinates);
            lineStrings[1] = jtsUtils.createLine(wheelCoordinates);
        }
        return lineStrings;
    }

    @Override
    public void updateCarPoints(List<PointBean> carPoints, List<PointExBean> carModelPoints, PointBean currentPoint, GpsInfoBean gpsInfo) {
        if (null != carModelPoints && carModelPoints.size() > 0) {
            for (int i = 0; i < carModelPoints.size(); i++) {
                if (null == carModelPoints.get(i)) {
                    continue;
                }
                PointExBean pointEx = new PointExBean();
                pointEx.setPoint(carModelPoints.get(i));
                pointEx.angle += gpsInfo.getAzimuth();
                pointEx.fixXY();
                pointEx.addXY(currentPoint);
                carPoints.get(i).setPoint(pointEx);
            }
        }
    }
}
